package com.example.demo.controller;
/*
 * @Desc 
 * @author 蔡超
 * @date 2018/9/21 10:42
 */

import com.example.demo.model.BdUserInfo;
import com.example.demo.service.UserService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping(value = "/users")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/{userId}")
    public BdUserInfo selectByUserId(@PathVariable String  userId){
        return userService.selectUser(userId);
    }

    @RequestMapping(value = "/query")
    public List<BdUserInfo> selectAll(HttpServletRequest request){
        int pageNum = Integer.parseInt(request.getParameter("pageNum"));
        int pageSize = Integer.parseInt(request.getParameter("pageSize"));
        return userService.selectUser(pageNum,pageSize);
    }

    @RequestMapping(value = "/add")
    public String addUser(@RequestBody BdUserInfo bdUserInfo){
        return userService.addUser(bdUserInfo);
    }

    @RequestMapping(value = "/update")
    public int updateUser(@RequestBody BdUserInfo bdUserInfo){
        return userService.updateUser(bdUserInfo);
    }

}
